home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Information / Programming / Stuart's Tech Notes / ATP sample code.c < prev    next >
Encoding:
Text File  |  1994-12-12  |  8.8 KB  |  107 lines  |  [TEXT/R*ch]

  1. etNum;
  2.         myNTE.nt.nteAddress.aNode   = ABusVars->sysLAPAddr;
  3.         myNTE.nt.nteAddress.aSocket = atp.ATPatpSocket;
  4.         
  5.         construct_name(myNTE.nt.nteAddress, regname);
  6.     
  7.         NBPSetNTE((Ptr)&myNTE,
  8.             (Ptr)regname, (Ptr)"\pMacintosh Authenticator", (Ptr)"\p*",
  9.             myNTE.nt.nteAddress.aSocket);
  10.         
  11.         p.p.MPPioCompletion = (ProcPtr)register_done;
  12.         p.p.NBPinterval     = 2;
  13.         p.p.NBPcount        = 8;
  14.         p.p.NBPntQElPtr     = (Ptr)&myNTE;
  15.         p.p.NBPverifyFlag   = TRUE;
  16.         asm { move.l GLOBREG, p.myglobals }
  17.         ErrorStatus = PRegisterName(&p.p, TRUE);
  18.         }
  19.     return(ErrorStatus);
  20.     }
  21.  
  22. local void AppleTalkShutDown(void)
  23.     {
  24.     if (ErrorStatus == noErr)
  25.         {
  26.         ATPParamBlock atpb;
  27.         MPPParamBlock p;
  28.         atpb.ATPatpSocket = myNTE.nt.nteAddress.aSocket;
  29.         PCloseATPSkt(&atpb, FALSE);
  30.         p.NBPentityPtr = myNTE.nt.entityData;
  31.         PRemoveName(&p, FALSE);
  32.         }
  33.     }
  34.  
  35. local long ATalkTransition(long selector, myATQEntry *atq, long param)
  36.     {
  37.     long *saveGptr;
  38.     asm    {    move.l    GLOBREG, saveGptr
  39.             move.l    atq, a0
  40.             move.l    myATQEntry.myglobals(a0), GLOBREG
  41.             cmp.l    #ATTransOpen, selector
  42.             bne.s    @1
  43.             bsr        AppleTalkStartUp
  44.             bra.s    @2
  45.         @1    cmp.l    #ATTransClose, selector
  46.             bne.s    @2
  47.             bsr        AppleTalkShutDown
  48.         @2    move.l    saveGptr, GLOBREG
  49.             clr.l    d0                    ; must return zero
  50.         }
  51.     }
  52.  
  53. /**************************************************************************************/
  54.  
  55. // This assembler is here because the LAPAddATQ and LAPRmvATQ calls provided by
  56. // Apple's nAppleTalk library have a bug which crashes the system when you call them
  57.  
  58. extern pascal OSErr my_LAPAddATQ(ATQEntryPtr theATQEntry);
  59. extern pascal OSErr my_LAPRmvATQ(ATQEntryPtr theATQEntry);
  60. local void assembler(void)
  61.     {
  62.     asm    {
  63.     extern my_LAPAddATQ:
  64.             move.w    #LAddAEQ, d0
  65.             bra.s    @1
  66.     extern my_LAPRmvATQ:
  67.             move.w    #LRmvAEQ, d0
  68.         @1    move.l    4(sp), a0
  69.             move.l    LAPMgrPtr, a1
  70.             move.l    (sp)+, (sp)
  71.             jsr        2(a1)
  72.             move.l    (sp)+, a0
  73.             move.w    d0, (sp)
  74.             jmp        (a0)
  75.         }
  76.     }
  77.  
  78. /**************************************************************************************/
  79.  
  80. // Init is used ONCE, when the program is first loaded, and
  81. // Quit would be called ONCE, finally, if the program exits
  82.  
  83. local OSErr AppleTalkInit(void)    // returns non-zero if init failed
  84.     {
  85.     short MPPRefNum;
  86.     SysEnvRec sysenvirons;
  87.     SysEnvirons(1, &sysenvirons);
  88.     ErrorStatus = OpenDriver("\p.MPP", &MPPRefNum);
  89.     if (ErrorStatus) return(ErrorStatus);
  90.     if (sysenvirons.atDrvrVersNum >= 53)
  91.         {
  92.         AppleTalkTransitionQueueEntry.e.CallAddr = (ProcPtr)ATalkTransition;
  93.         asm { move.l GLOBREG, AppleTalkTransitionQueueEntry.myglobals }
  94.         ErrorStatus = my_LAPAddATQ(&AppleTalkTransitionQueueEntry.e);
  95.         if (ErrorStatus) return(ErrorStatus);
  96.         }
  97.     return(AppleTalkStartUp());
  98.     }
  99.  
  100. local void AppleTalkQuit(void)
  101.     {
  102.     SysEnvRec sysenvirons;
  103.     SysEnvirons(1, &sysenvirons);
  104.     if (sysenvirons.atDrvrVersNum >= 53) my_LAPRmvATQ(&AppleTalkTransitionQueueEntry.e);
  105.     AppleTalkShutDown();
  106.     }
  107.